<?php

require "./php_utils/utils.php";
execute();




function execute() {
    $data = new StdClass;

    enrichFromFile($data, "main.properties");

    $sections = parseFileNames("content");

    $data->sections = array();
    foreach ($sections as $sectionElement) {
        array_push($data->sections, createSection($sectionElement));
    }

    echo json_encode($data);
}

function createSection($sectionElement) {
    $section = new Section();
    $section->name = $sectionElement->name;

    $items = parseFileNames("content/" . $sectionElement->fileName);

    foreach ($items as $itemElement) {
        array_push($section->items, createItem($sectionElement->fileName, $itemElement));
    }
    return $section;
}

function createItem($sectionFileName, $itemElement) {
    $item = new StdClass;
    $itemPath = "content/" . $sectionFileName . "/" . $itemElement->fileName;

    enrichFromFile($item, $itemPath . "/item.properties");

    $images = getFileNames($itemPath . "/images");
    $item->images = array();
    foreach ($images as $imageFileName) {
        array_push($item->images, $itemPath . "/images/" . $imageFileName);
    }

    $item->iconPath = getIconPath($itemPath);

    return $item;
}

?>



